<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/header.jsp"%>
<c:set var="path" value="../..${ctx}/define/menu" />
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pagination 分页表格</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="${ctx}/demo/demo.css" rel="stylesheet" type="text/css" />
<script src="${ctx}/scripts/boot.js" type="text/javascript"></script>
<script src="${ctx}/common/common.js" type="text/javascript"></script>
<style type="text/css">
html,body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
}
</style>
</head>
<body>

<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
	<a class="mini-button" iconCls="icon-save" plain="true" onclick="saveData()">保存</a>
</div>

<form id="form1" method="post">
   <input id="actionType" name="actionType" type="hidden" value="search" />
   <div id="editForm1" style="padding:5px;">
       <!--<input class="mini-hidden" name="id"/>-->
       <table style="width:100%;">
           <tr>
               <td style="width:100px;">操作单元名称：</td>
               <td><input id="name" name="name" class="mini-textbox" width="260" /></td>
               <td style="width:60px;">分类：</td>
               <td><input id="sort" name="sort" class="mini-textbox" width="260" /></td>
           </tr>
           <tr>
               <td>起用缓存：</td>
               <td>
               <div id="cache" name="cache" class="mini-checkbox" checked="true" readOnly="false" />
               </td>
               <td></td>
               <td></td>
          </tr>
          <tr>
               <td>SQL文：</td>
               <td colspan="3"><input id="sql" name="sql" class="mini-textarea" style="width:680px;height:120px;" /></td>
           </tr>
           <tr>
               <td>操作说明：</td>
               <td colspan="3"><textarea id="description" name="description" class="mini-textarea" emptyText="请输入备注" style="width:680px;height:60px;"></textarea></td>
           </tr>
       </table>
   </div>
</form>

<div class="header" region="north" height="10" showSplitIcon="true" showHeader="false">
	<h1 style="margin: 0; padding: 5px; cursor: default; font-family: 'Trebuchet MS', Arial, sans-serif;"></h1>
</div>

<div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
	<a class="mini-button" iconCls="icon-add" plain="true" onclick="addRow()">添加</a> 
	<a class="mini-button" iconCls="icon-remove" plain="true" onclick="removeRow()">删除</a> 
</div>

<div id="grid1" class="mini-datagrid"
	style="width: 100%; height: 100%;" borderStyle="border:0;"
	url="${path}/getTable.html"
	allowCellSelect="true" allowCellEdit="true" allowSortColumn="false" showPager="false" showModified="true">
	<div property="columns">
		<div name="fieldName" field="fieldName" headerAlign="center" allowSort="true" width="150">
			数据库字段名 <input property="editor" class="mini-textbox" style="width: 100%;" minWidth="100" />
		</div>
		<div name="searchName" field="searchName" headerAlign="center" allowSort="true" width="150">
			查询语句字段名 <input property="editor" class="mini-textbox" style="width: 100%;" minWidth="100" />
		</div>
		<div name="replaceName" field="replaceName" headerAlign="center" allowSort="true" width="300">
			替换查询语句 <input property="editor" class="mini-textbox" style="width: 100%;" minWidth="300" />
		</div>
		<div type="comboboxcolumn" name="type" field="type" headerAlign="center" allowSort="true" width="80">
			数据类型 <input property="editor" class="mini-combobox" url="../..${ctx}/define/dbmeta/getDataType.html" style="width: 100%;" minWidth="80" />
		</div>
		<div name="format" field="format" headerAlign="center" allowSort="true" width="100">
			格式 <input property="editor" class="mini-textbox" style="width: 100%;" minWidth="100" />
		</div>
		<div name="defaultValue" field="defaultValue" headerAlign="center" allowSort="true" width="100">
			默认值<input property="editor" class="mini-textbox" style="width: 100%;" minWidth="100" />
		</div>
		<div type="checkboxcolumn" name="force" field="force" trueValue="1" falseValue="0" width="40" headerAlign="center">强制</div> 
	</div>
</div>


<script type="text/javascript">
mini.parse();
var grid = mini.get("grid1");
var form = new mini.Form("#form1");

/*********************************************************
 * 用户按钮操作方法
 *********************************************************/
	/**
	 * 新增字段
	 */
	function addRow() {
		var newRow = {
			force : false,
			type : "定长文本"
		};
		grid.addRow(newRow, grid.getData().length);
	}
	/**
	 * 删除字段
	 */
	function removeRow() {
		var rows = grid.getSelecteds();
		if (rows.length > 0) {
			grid.removeRows(rows, true);
		}
	}
	/**
	 * 保存
	 */
	function saveData() {
        form.validate();
        if (form.isValid() == false) return;
		var gd = mini.encode(grid.getChanges());
		var fd = mini.encode(form.getData());
		grid.loading("保存中，请稍后......");
		$.ajax({
			url : "${path}/saveSearchAction.html",
			data : {
				action : fd,
				params : gd
			},
			type : "post",
			cache: false,
			success : function(text) {
				CloseWindow("save");
			},
			error : function(jqXHR, textStatus, errorThrown) {
				grid.unmask();
				CloseWindow();
			}
		});
	}
</script>

</body>
</html>